package stringStudy;

import java.util.Arrays;

public class FirstNotRepeatingChar {

    /**
     * JZ34 第一个只出现一次的字符
     * @param args
     */
    public static void main(String[] args) {
        System.out.println(FirstNotRepeatingChar("sxvLtVYEiFzvcmJOzEKCWfUeSsHOpCbLQYiiFjDGvlYaOyEuhiSShuzg"));
    }

    public static int FirstNotRepeatingChar(String str) {
        int[] arr = new int[52];
        Arrays.fill(arr, -1);
        for (int i = 0; i < str.length(); i++){
            int num = str.charAt(i);
            int index;
            if (num < 80){
                index = num - 'A';
            } else {
                index = num - 'a' + 26;
            }
            if (arr[index] == -1){
                arr[index] = i;
            } else {
                arr[index] = Integer.MAX_VALUE;
            }
        }
        int res = Integer.MAX_VALUE;
        for (int i = 0; i < 52; i++){
            if (arr[i] != -1 && arr[i] < res){
                res = arr[i];
            }
        }
        return res == Integer.MAX_VALUE ? -1 : res;
    }
}
